/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package info.touret.winecellar.reminder;

import info.touret.winecellar.bottle.server.domain.Bottle;
import info.touret.winecellar.userinfo.server.domain.UserInfo;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.log4j.Logger;

import com.google.inject.Inject;

/**
 * 
 * @author touret-a
 */
public class SendReminderInterceptor implements MethodInterceptor {

	@Inject
	private ReminderService reminderService;
	private static final Logger trace = Logger
	.getLogger(LocalCalendarServiceFactory.class);


	@Override
	public Object invoke(MethodInvocation invocation) throws Throwable {
		Object invoker = invocation.proceed();
		Bottle bottle = (Bottle) invocation.getArguments()[0];
		UserInfo user = (UserInfo) invocation.getArguments()[2];
		trace.info("Creation d'un evenement " + bottle.toString() + " - "
				+ user.toString());
		reminderService.createEvent(bottle, user);
		trace.info("Evenement cree pour " + bottle.toString());
		return invoker;
	}
}
